//
//  KYPersonalInfoViewController.m
//  个人信息修改
//
//  Created by Yip-Jun on 16/5/3.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZPersonalInfoViewController.h"
#import "YZPesonalInfoCell.h"
#import "YZHeaderView.h"
#import "YZCoverView.h"
//#import "Masonry.h"

NSString *ReuseIdentifierCell = @"ReuseIdentifierCell";
NSString *ReuseIdentifierHeaderView = @"ReuseIdentifierHeaderView";

@interface YZPersonalInfoViewController ()

@property (nonatomic, strong) NSIndexPath *coverIndexPath;

@property (nonatomic, strong) NSArray *messages;
// 弹出窗口
@property (nonatomic, strong) YZCoverView *coverView;

//@property (nonatomic, copy) NSString *titleString;

@property (nonatomic, strong) UILabel *titleView;

@end

@implementation YZPersonalInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.titleView = self.titleView;
//    self.title = @"个人信息修改";
//    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName : [UIFont systemFontOfSize:18], NSForegroundColorAttributeName : [UIColor whiteColor]};
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[YZPesonalInfoCell class] forCellReuseIdentifier:@"ReuseIdentifierCell"];
    self.tableView.tableHeaderView = [YZHeaderView headerView];
    
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.messages.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    YZPesonalInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseIdentifierCell"];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.message = self.messages[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    NSLog(@"tableView: didSelectRowAtIndexPath: %zd", indexPath.row);
    
    self.tableView.scrollEnabled = NO;
    self.coverIndexPath = indexPath;
    
    [self addCoverView];
    self.coverView.indexPath = indexPath;
    self.coverView.message = self.messages[indexPath.row];
}

- (void)addCoverView {
    
    [self.view addSubview:self.coverView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 44;
}

- (NSArray *)messages {
    if (!_messages) {
        _messages = [NSMutableArray arrayWithObjects:@"身高", @"体重", @"省份", nil];
    }
    return _messages;
}

- (YZCoverView *)coverView {
    if (!_coverView) {
        _coverView = [YZCoverView coverView: self.coverIndexPath];
        _coverView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        // 设置遮挡 view 的颜色以及透明度
        _coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        __weak __typeof(self)weakSelf = self;
        _coverView.cannelBtnDidClickBlock = ^ {
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.coverView.alpha = 0;
            } completion:^(BOOL finished) {
                [weakSelf.coverView removeFromSuperview];
                weakSelf.coverView = nil;
            }];
        };
        _coverView.pushBtnDidClickBlock = ^ {
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.coverView.alpha = 0;
            } completion:^(BOOL finished) {
                [weakSelf.coverView removeFromSuperview];
                weakSelf.coverView = nil;
                [weakSelf.tableView reloadData];
            }];
        };
    }
    return _coverView;
}

- (UILabel *)titleView {
    if (!_titleView) {
        _titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        _titleView.text = @"个人信息修改";
        _titleView.textColor = [UIColor whiteColor];
//        _titleView.font = [UIFont systemFontOfSize:16];
        [_titleView setFont:[UIFont fontWithName:@"Helbetica Neue-Bold" size:18]];
        _titleView.textAlignment = NSTextAlignmentCenter;
    }
    return _titleView;
}

@end
